<template>
  <div class="customerUpdateOne">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="客户名称" prop="companyName">
            <el-input v-model="form.companyName" placeholder="请输入客户名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="客户类型" prop="companyType">
            <el-select v-model="form.companyType" placeholder="请选择客户类型">
              <el-option
                v-for="dict in dict.type.company_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="联系人" prop="name">
            <el-input v-model="form.name" placeholder="请输入联系人"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="mobile">
            <el-input v-model="form.mobile" placeholder="请输入联系电话" maxlength="11"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="是否优质企业" prop="hot">
            <el-select v-model="form.hot" placeholder="请输入是否优质企业">
              <el-option
                v-for="dict in [{label:'是',value:0},{label:'否',value:1}]"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结束时间" prop="registerendTime">
            <el-date-picker
              v-model="form.registerendTime"
              type="date"
              placeholder="请输入结束时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="通讯地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入通讯地址"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="客户状态" prop="companyStatus">
            <el-select v-model="form.companyStatus" placeholder="请选择客户类型">
              <el-option
                v-for="dict in dict.type.company_status"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="所属行业名称" prop="industryname">
            <el-input v-model="form.industryname" placeholder="请输入所属行业名称"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="经营状态" prop="managementType">
            <el-input v-model="form.managementType" placeholder="请输入经营状态"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="企业性质" prop="companyNature">
            <el-input v-model="form.companyNature" placeholder="请输入企业性质"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="登记机关" prop="registrationAuthority">
            <el-input v-model="form.registrationAuthority" placeholder="请输入登记机关"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="法人" prop="legalPerson">
            <el-input v-model="form.legalPerson" placeholder="请输入法人"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="职务" prop="post">
            <el-input v-model="form.post" placeholder="请输入职务"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规模" prop="scale">
            <el-input v-model="form.scale" placeholder="请输入规模"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="注册地址" prop="companyAddress">
            <el-input v-model="form.companyAddress" placeholder="请输入注册地址"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属国家" prop="companyCountry">
            <el-input v-model="form.companyCountry" placeholder="请输入所属国家"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="联系邮箱" prop="email">
            <el-input v-model="form.email" placeholder="请输入联系邮箱"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="注册资金" prop="registerMoney">
            <el-input v-model="form.registerMoney" placeholder="请输入注册资金"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="注册成立时间" prop="registerTime">
            <el-input v-model="form.registerTime" placeholder="请输入注册成立时间"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="统一信用代码" prop="socialCreditCode">
            <el-input v-model="form.socialCreditCode" placeholder="请输入统一信用代码"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="技术领域" prop="technicalField">
            <el-input v-model="form.technicalField" placeholder="请输入技术领域"/>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="客户名头像" prop="companyLogo">
            <imageUpload v-model="form.companyLogo"/>
            <div class="hint">尺寸建议：宽160px，高160px</div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="客户图片集" prop="companyImgs">
            <imageUpload v-model="form.companyImgs"/>
            <div class="hint">尺寸建议：宽160px，高160px</div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="客户描述" prop="companyDesc">
            <el-input type="textarea" rows="5" v-model="form.companyDesc" placeholder="请输入客户描述"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="营业范围" prop="businessScope">
            <el-input type="textarea" rows="5" v-model="form.businessScope" placeholder="请输入营业范围"/>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="footer">
        <el-button @click="cancel">关闭</el-button>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </div>
    </el-form>
  </div>
</template>
<style lang="scss">
  .customerUpdateOne {
    .el-form-item {
      margin: 0;

      .el-form-item__label {
        width: 100px !important;
      }

      .el-form-item__content {
        margin-left: 100px !important;
      }
    }

    .el-select .el-input {
      width: auto;
    }

    .synchronization {
      display: flex;
      align-items: center;

      .el-form-item {
        flex: 1;
      }

      .el-button {
        margin: 0;
        margin-left: 10px;
      }
    }

    .footer {
      display: flex;
      justify-content: center;

      .el-button {
        margin: 15px;
      }
    }

    .hint {
      color: #8C8C8C;
    }
  }
</style>
<script>
  import {addCustomer, updateCustomer} from "@/api/customer/customer";
  export default {
    dicts: ['company_type', 'company_status'],
    props:['form'],
    data() {
      return {
        rules: {
          companyName: [
            {required: true, message: "联系人不能为空！", trigger: "blur"}
          ],
          companyType: [
            {required: true, message: "客户类型不能为空！", trigger: "blur"}
          ],
          name: [
            {required: true, message: "联系人不能为空！", trigger: "blur"}
          ],
          mobile: [{
            validator: this.conductionData.commonFun.checkPhone,
            trigger: 'blur',
            required: true,
          }]
        }
      };
    },
    created() {
    },
    methods: {
      synchronization() {

      },
      // 返回
      cancel() {
        this.$emit("ComponentType", "detailsOne");
        this.$router.go(-1);
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCustomer(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.$router.go(-1);
              });
            } else {
              addCustomer(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.$router.go(-1);
              });
            }
          }else{
            this.$modal.msgError("请输入正确格式信息！");
          }
        });
      }
    }
  };
</script>
